#include<iostream>
using namespace std;
namespace bit
{
	template<class T>
	struct Node
	{
		T val;
		Node* next;
		Node(T x):val(x), next(nullptr)
		{}
	};

	template<class T>
	class list
	{
	private:
		bit::Node<T>* head;
	public:
		list():head(nullptr)//一定不能丢了这个初始化
		{}
		void print()
		{
			Node<int>* temp = head;
			while (temp)
			{
				cout << temp->val << endl;
				temp = temp->next;
			}
		}
		void push(const T& x)//头插
		{
		/*	newnode* node =  new Node(x);
			newnode->next = phead;
			phead = newnode;*///这写的啥

			Node<T>* newnode = new Node<T>(x);
			newnode->next = head;
			head = newnode;
		}

		void append(const T& x)
		{
			Node<T>* newnode = new Node<T>(x);
			if (!head)
			{
				head = newnode;//注意
			}
			else
			{
				Node<T>* tail = head;
				//while(tail)注意这里
				while (tail->next)
				{
					tail = tail->next;
				}
				tail->next = newnode;
			}
		}

		void remove(const T& x)
		{
			if (!head) return;
			Node<T>* temp = head;
			Node<T>* prev = nullptr;
			while (temp)
			{
				if (temp->val == x)
				{
					if (prev)
					{
						prev->next = temp->next;
					}
					else
					{
						head = temp->next;
					}

					delete temp;
					return ;
				}

				prev = temp;
				temp = temp->next;
			}

		}

		~list()
		{
			Node<T>* temp;
			while (head)
			{
				temp = head;
				head = head->next;
				delete temp;

			}
		}

		
	};


	


}


int main()
{
	bit::list<int> s;
	s.push(1);
	s.push(2);
	s.print();
	s.append(3);
	s.remove(2);

	s.print();

	return 0;
}